//
//  BreakFastModel.m
//  JackDeve
//
//  Created by Agensn on 2017/5/14.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "BreakFastModel.h"

static BreakFastModel *model = nil;

@implementation BreakFastModel

+(BreakFastModel *)model{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        model = [[BreakFastModel alloc]init];
        
    });
    return model;
}

-(void)getBreakFastData{
    Data *data = [HomeUserDefault getUserDefault];
    
    NSString *url = [NSString stringWithFormat:@"%@/diner/index?diner_id=1&token=%@",ROOT_URL,data.token];
    
    NSLog(@"=======%@",url);
//    
//    NSURLSession *session = [NSURLSession sharedSession];
//    
//    NSURLSessionDataTask *task = [session dataTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//        NSDictionary *dic = (NSDictionary *)response;
//        NSLog(@"//////////////////////////%@",dic);
//        
//        SDBreakFastModel *model = [SDBreakFastModel yy_modelWithJSON:dic];
//        NSLog(@"%@",model.data);
//        SDBreakData *SDData = [SDBreakData yy_modelWithDictionary:model.data];
//        NSLog(@"---------%@",SDData.goods);
//    }];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [[AFHTTPResponseSerializer alloc]init];
    NSURLSessionDataTask *task = [manager dataTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]] completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
        
        NSDictionary *dic = (NSDictionary *)responseObject;
        NSLog(@"//////////////////////////%@",dic);
        
        SDBreakFastModel *model = [SDBreakFastModel yy_modelWithJSON:dic];
        NSLog(@"%@",model.data);
        SDBreakData *SDData = [SDBreakData yy_modelWithDictionary:model.data];
        NSLog(@"---------%@",SDData.goods);

        [[NSNotificationCenter defaultCenter]postNotificationName:@"SDBreakData" object:SDData];
    }];
    [task resume];

}

@end
